package io.modifier.basic.core

import android.annotation.SuppressLint
import android.content.Context
import android.net.wifi.WifiManager

object Ip {

    fun getIPAddress(context: Context): String {

        fun intIP2StringIP(ip: Int): String {
            return (ip and 0xFF).toString() + "." +
                    ((ip shr 8) and 0xFF) + "." +
                    ((ip shr 16) and 0xFF) + "." +
                    (ip shr 24 and 0xFF)
        }

        val wifiManager = context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
        @SuppressLint("MissingPermission") val wifiInfo = wifiManager.connectionInfo
        val ipAddress: String = intIP2StringIP(wifiInfo.ipAddress)
        return ipAddress
    }

}